package com.jet.chat.command;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.jet.chat.message.Message;
import com.jet.chat.server.ChatServer;
import com.jet.chat.server.ChatSession;

public class CCWhisperParams extends CCParamsAbstract {
	
	private boolean parsed;
	private String error;	
	private String username;
	private String content;
	
	public CCWhisperParams(ChatServer chatServer, ChatSession chatSession, Message message) {
		super(chatServer, chatSession, message);
		
		Pattern pattern = Pattern.compile("^/\\w+\\s(\\w+)\\s(.*)$");
		Matcher matcher = pattern.matcher(message.getContent());
		
		if (!matcher.matches()) {
			this.parsed = false;
			this.error = "invalid command format. usage: '/w username message'";
		} else {
			this.parsed = true;
			this.username = matcher.group(1);
			this.content = matcher.group(2);
		}
	}

	public String getUsername() {
		return username;
	}

	public String getContent() {
		return content;
	}

	public boolean isParsed() {
		return parsed;
	}

	public String getError() {
		return error;
	}
	
}
